import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/module_permissions_util.dart';
import 'package:enterprise_v6_app/app/data/entities/application/securtity_base_drawer.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/case/case_view.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/communicate/communicate_local.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/communicate/communticate_territorial.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/drill/drill_plan/drill_plan_view.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/drill/drill_record/drill_record_view.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/emergency_plan/emergency_plan_view.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/event/event_view.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/home/home_view.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/resource/resource_view.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

class EmergencyController extends GetxController {
  /// scaffoldKey
  final scaffoldKey = GlobalKey<ScaffoldState>();

  /// 选中的页面
  int selectIndex = 0;

  final titleList = [
    SecurityBaseEntity(
      title: '总览',
      icon: AppImages.icon_inspection_drawer_4,
      expandTitle: '总览',
      currentPageTitle: 0,
      pages: [EmergencyHomePage()],
      path: '/home',
    ),
    SecurityBaseEntity(
      title: '应急预案',
      icon: AppImages.icon_emergency_plan,
      expandTitle: '应急预案',
      currentPageTitle: 0,
      pages: [EmergencyPlanPage()],
      path: '/emergencyPlan',
    ),
    SecurityBaseEntity(
      title: '应急资源',
      icon: AppImages.icon_emergency_resource,
      expandTitle: '应急资源',
      currentPageTitle: 0,
      pages: [EmergencyResourcePage()],
      path: '/emergencyResource',
    ),
    SecurityBaseEntity(
      title: '应急演练',
      icon: AppImages.icon_emergency_drill,
      expandTitle: '应急演练',
      currentPageTitle: 0,
      pageTitle: ['演练计划', '演练记录'],
      pages: [
        DrillPlanPage(),
        DrillRecordPage(),
      ],
      path: '/drill',
    ),
    SecurityBaseEntity(
      title: '应急通讯',
      icon: AppImages.icon_emergency_communication,
      expandTitle: '应急通讯',
      currentPageTitle: 0,
      pageTitle: ['本企通讯', '属地通讯'],
      pages: [
        const CommunicateLocalPage(),
        const CommunicateTerritorialPage(),
      ],
      path: '/communicate',
    ),
    SecurityBaseEntity(
      title: '事故事件',
      icon: AppImages.icon_sask_major_hazards,
      expandTitle: '事故事件',
      currentPageTitle: 0,
      pages: [EventPage()],
      path: '/event',
    ),
    SecurityBaseEntity(
      title: '事故案例库',
      icon: AppImages.icon_equipment_facilities,
      expandTitle: '事故案例库',
      currentPageTitle: 0,
      pages: [CasePage()],
      path: '/accidentCase',
    ),
  ];

  @override
  void onInit() {
    super.onInit();
    initModule();
  }

  /// 根据后台权限初始化菜单
  void initModule() {
    ModulePermissionsUtil.removeRoleMenu(titleList: titleList, routes: AppRoutes.emergency);
    update();
  }

  /// title选择切换
  /// [titleIndex] 标题索引
  /// [index] 页面索引
  void selectTitle(int titleIndex, int index) {
    titleList[titleIndex].currentPageTitle = index;
    update();
  }

  /// 点击左侧菜单
  /// [index] 索引
  void selectLeftMenu(int index) {
    selectIndex = index;
    update();
  }

  /// 点击展开菜单
  /// [index] 索引
  void selectExpandMenu(int index) {
    selectIndex = index;
    Get.back();
    update();
  }
}
